package xyz.jcat.biz.admin.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import org.springframework.stereotype.Service;

import xyz.jcat.biz.admin.domain.dto.UserAddDto;
import xyz.jcat.biz.admin.domain.vo.UserInfoVo;
import xyz.jcat.common.util.CodeUtils;
import xyz.jcat.common.util.CopyUtils;
import xyz.jcat.mybatis.ServiceImpl;
import xyz.jcat.biz.admin.domain.po.UserPo;
import xyz.jcat.biz.admin.domain.dao.IUserDao;
import xyz.jcat.biz.admin.service.IUserService;
/**
 *
 * @author yueyue
 * auto on 2022-04-28 13:41:47
 */
@Service
public class UserService extends ServiceImpl<IUserDao, UserPo> implements IUserService {

    @Override
    public UserPo getByUsername(String username) {
        LambdaQueryWrapper<UserPo> lambdaQueryWrapper = new LambdaQueryWrapper<>();
        lambdaQueryWrapper.eq(UserPo::getUsername, username);
        return getOne(lambdaQueryWrapper);
    }

    @Override
    public UserInfoVo getUserInfo(Long id) {
        UserPo user = getById(id);
        UserInfoVo vo = CopyUtils.copy(user, new UserInfoVo());
        return vo;
    }

    @Override
    public void addUser(UserAddDto userAddDto) {
        UserPo user = CopyUtils.copy(userAddDto, new UserPo());
        user.setPassword(CodeUtils.pwdEncrypt(user.getUsername(), 6));
        insert(user);
    }
}
